package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.entity.brand.Brand;
import com.atguigu.spzx.model.entity.category.CategoryBrand;
import com.atguigu.spzx.model.vo.category.CategoryBrandVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/5
 * description：
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    @Override
    public PageInfo<CategoryBrandVo> list(Integer pageNum, Integer pageSize, CategoryBrand categoryBrand) {
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        //查询数据库
        List<CategoryBrandVo> list = categoryBrandMapper.selectByPage(categoryBrand);
        //返回pageInfo
        return new PageInfo<>(list);
    }

    @Override
    public void deleteCategoryBrand(Long id) {
        categoryBrandMapper.deleteCategoryBrand(id);
    }

    @Override
    public void saveCategoryBrand(CategoryBrand categoryBrand) {
        categoryBrandMapper.saveCategoryBrand(categoryBrand);
    }

    @Override
    public void updateCategoryBrand(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateCategoryBrand(categoryBrand);
    }

    @Override
    public CategoryBrand getCategoryBrand(Long id) {
        return categoryBrandMapper.getCategoryBrand(id);
    }

    @Override
    public List<Brand> getBrandByCategoryId(Long categoryId) {
        return categoryBrandMapper.getBrandByCategoryId(categoryId);
    }
}
